<?php 

//登陆认证 
$url = "http://forum.XXX.edu.cn/login?form=default"; 
$post_data = array( "id" => "username","passwd" => "password" ); 

$cookie_jar = tempnam('./temp','cookie');//存放COOKIE的文件 

$ch = curl_init(); 

curl_setopt($ch, CURLOPT_URL, $url); 

curl_setopt($ch, CURLOPT_POST, 1); 

curl_setopt($ch, CURLOPT_HEADER, 0); 

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); 

curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);   

curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);  //保存cookie信息 

$output1 = curl_exec($ch); 

curl_close($ch); 


/*发帖操作*/ 

$url = "http://forum.XXXX.edu.cn/XXXXX/XXXXX"; 

$data = array("subject" =>'test_roy',"content" => 'curlphphahahha',"signature" => '0',"reid" =>'0'); 


$ch = curl_init(); 

curl_setopt($ch, CURLOPT_URL, $url); 

curl_setopt($ch, CURLOPT_REFERER, $url);       //伪装REFERER 

curl_setopt($ch, CURLOPT_POST, 1);   //post方式提交数据 

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);   //返回数据，而不是直接输出 

curl_setopt($ch, CURLOPT_HEADER, 0);   // 设置是否显示header信息 0是不显示，1是显示  默认为0 

curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar);  //发送cookie文件 

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);   //发送POST数据 

$output2 = curl_exec($ch);    //发送HTTP请求 

curl_close($ch); 



//清理cookie文件 
unlink($cookie_jar); 


?> 